package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.TextArea;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerPrincipal;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;

import javax.swing.ImageIcon;

public class TelaCadastrarTratamentos extends JFrame {

	private JPanel contentPane;
	static JTextField txt_dataInicio;
	static JTextField txt_dataTermino;
	static JTextField txt_hospitalClinica;
	static JTextField txt_medico;
	static TextArea text_instrucoes;
	static Integer codAletrar;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaCadastrarTratamentos frame = new TelaCadastrarTratamentos();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaCadastrarTratamentos() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 840, 540);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblTratamento = new JLabel("Tratamento");
		lblTratamento.setForeground(new Color(0, 0, 128));
		lblTratamento.setFont(new Font("Franklin Gothic Medium Cond", Font.PLAIN, 25));
		lblTratamento.setBounds(28, 23, 112, 34);
		contentPane.add(lblTratamento);
		
		JLabel lblDataDeIncio = new JLabel("Data de In\u00EDcio:");
		lblDataDeIncio.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDataDeIncio.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDataDeIncio.setBounds(57, 77, 124, 19);
		contentPane.add(lblDataDeIncio);
		
		txt_dataInicio = new JTextField();
		txt_dataInicio.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_dataInicio.setColumns(10);
		txt_dataInicio.setBounds(191, 74, 124, 23);
		contentPane.add(txt_dataInicio);
		
		txt_dataTermino = new JTextField();
		txt_dataTermino.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_dataTermino.setColumns(10);
		txt_dataTermino.setBounds(191, 107, 124, 23);
		contentPane.add(txt_dataTermino);
		
		JLabel lblDataDoTrmino = new JLabel("Data de T\u00E9rmino:");
		lblDataDoTrmino.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDataDoTrmino.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDataDoTrmino.setBounds(57, 109, 124, 19);
		contentPane.add(lblDataDoTrmino);
		
		JLabel label_3 = new JLabel("Hospital/Cl\u00EDnica:");
		label_3.setHorizontalAlignment(SwingConstants.RIGHT);
		label_3.setFont(new Font("Arial", Font.PLAIN, 14));
		label_3.setBounds(57, 142, 124, 19);
		contentPane.add(label_3);
		
		txt_hospitalClinica = new JTextField();
		txt_hospitalClinica.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_hospitalClinica.setColumns(10);
		txt_hospitalClinica.setBounds(191, 139, 377, 23);
		contentPane.add(txt_hospitalClinica);
		
		txt_medico = new JTextField();
		txt_medico.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_medico.setColumns(10);
		txt_medico.setBounds(191, 173, 377, 23);
		contentPane.add(txt_medico);
		
		JLabel label_4 = new JLabel("M\u00E9dico:");
		label_4.setHorizontalAlignment(SwingConstants.RIGHT);
		label_4.setFont(new Font("Arial", Font.PLAIN, 14));
		label_4.setBounds(57, 176, 124, 19);
		contentPane.add(label_4);
		
		JLabel lblInstrues = new JLabel("Instru\u00E7\u00F5es:");
		lblInstrues.setHorizontalAlignment(SwingConstants.RIGHT);
		lblInstrues.setFont(new Font("Arial", Font.PLAIN, 14));
		lblInstrues.setBounds(101, 206, 80, 19);
		contentPane.add(lblInstrues);
		
		text_instrucoes = new TextArea();
		text_instrucoes.setBounds(191, 207, 380, 209);
		contentPane.add(text_instrucoes);
		
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String dataInicio = txt_dataInicio.getText();
				String dataTermino = txt_dataTermino.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String instrucoes = text_instrucoes.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				control.InserirTratamento(dataInicio, dataTermino, local, medico, instrucoes);
				TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
				telaMensagem.setLocationRelativeTo(null);
				telaMensagem.setVisible(true);
				txt_dataInicio.setText("");
				txt_dataTermino.setText("");
				txt_hospitalClinica.setText("");
				txt_medico.setText("");
				text_instrucoes.setText("");
			}
		});
		btnSalvar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSalvar.setBounds(433, 434, 100, 43);
		contentPane.add(btnSalvar);
		
		JButton btnSair = new JButton("Sair");
		btnSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnSair.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSair.setBounds(543, 434, 100, 43);
		contentPane.add(btnSair);
		
		JButton button_2 = new JButton("Deletar");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataInicio = txt_dataInicio.getText();
				String dataTermino = txt_dataTermino.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String instrucoes = text_instrucoes.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.deletarTratamento(codAletrar, dataInicio, dataTermino, local, medico, instrucoes);
					TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataInicio.setText("");
					txt_dataTermino.setText("");
					txt_hospitalClinica.setText("");
					txt_medico.setText("");
					text_instrucoes.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		button_2.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button_2.setBackground(Color.WHITE);
		button_2.setBounds(323, 434, 100, 43);
		contentPane.add(button_2);
		
		JButton btnAlterar = new JButton("Alterar");
		btnAlterar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataInicio = txt_dataInicio.getText();
				String dataTermino = txt_dataTermino.getText();
				String local = txt_hospitalClinica.getText();
				String medico = txt_medico.getText();
				String instrucoes = text_instrucoes.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.editarTratamento(codAletrar, dataInicio, dataTermino, local, medico, instrucoes);
					TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataInicio.setText("");
					txt_dataTermino.setText("");
					txt_hospitalClinica.setText("");
					txt_medico.setText("");
					text_instrucoes.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		btnAlterar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnAlterar.setBackground(Color.WHITE);
		btnAlterar.setBounds(211, 434, 100, 43);
		contentPane.add(btnAlterar);
		
		JButton btnListar = new JButton("Listar");
		btnListar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TelaListarTratamentos telaListaTratamento = new TelaListarTratamentos();
				telaListaTratamento.setLocationRelativeTo(null);
				telaListaTratamento.setVisible(true);
			}
		});
		btnListar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnListar.setBackground(Color.WHITE);
		btnListar.setBounds(101, 434, 100, 43);
		contentPane.add(btnListar);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("arquivos\\FundoCadastros.png"));
		label.setBounds(0, 0, 834, 511);
		contentPane.add(label);
	}

}
